home *** CD-ROM | disk | FTP | other *** search
Text File | 1993-06-10 | 6.5 KB | 220 lines | [TEXT/MPS ] |
- //----------------------------------------------------------------------------------------
- // TWindowMenuApp::DoMenuCommand:
- //----------------------------------------------------------------------------------------
- #pragma segment ASelCommand
- pascal void TWindowMenuApp::DoMenuCommand(CommandNumber aCommandNumber) // Override
- {
- short menu, item;
- CommandToComponents(aCommandNumber, menu,item);
- if(aCommandNumber < 0) // negative items are our window names!
- DoWindowsMenuItem(item);
-
- else {
- switch (aCommandNumber)
- {
- // Your menu items go here
-
- case cCascade:
- this->CascadeWindows();
- break;
-
- case cCloseAll:
- this->CloseAllWindows();
- break;
-
- default:
- inherited::DoMenuCommand(aCommandNumber);
- break;
- }
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TWindowMenuApp::DoSetupMenus:
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
- pascal void TWindowMenuApp::DoSetupMenus()
- {
- inherited::DoSetupMenus();
-
- // Stuff to enable your menu items goes here
-
- Enable(cCloseAll, true);
- Enable(cCascade, true);
-
- BuildWindowMenu();
-
- MenuHandle windowsMenu = MAGetMenu(mWindows);
- short itemCount = CountMItems(windowsMenu);
-
- // ASSumption Alert - hard coded number of standard items in menu = 3
- // Close All
- // Cascade
- // -------- (Gray dashed line)
-
- for(short item=itemCount; item>3; item--) {
- EnableItem(windowsMenu,item);
- }
- }
- //----------------------------------------------------------------------------------------
- // TWindowMenuApp::BuildWindowMenu:
- //----------------------------------------------------------------------------------------
- #pragma segment MAMenuRes
- pascal void TWindowMenuApp::BuildWindowMenu()
- {
- CStr255 itsTitle;
- MenuHandle windowsMenu = MAGetMenu(mWindows);
-
- // ASSumption Alert - hard coded number of standard items in menu = 3
- // Close All
- // Cascade
- // -------- (Gray dashed line)
-
-
- short itemCount = CountMItems(windowsMenu);
- for(short item=itemCount; item>3; item--) {
- DelMenuItem(windowsMenu,item);
- }
-
- TList *listOfWindows = MakeWindowList();
- for(ArrayIndex i = 1; i<=listOfWindows->GetSize(); i++) {
- TWindow *aWindow = (TWindow *)listOfWindows->At(i);
-
- // Here we're being *REAL* careful. The thing must be:
- // 1) an Object
- // 2) a TWindow
- // 3) Visible
- // The reason for all this is that MacApp maintains at least 1 offscreen
- // window that we need to ignore (the clipboard window).
-
- if(IsObject(aWindow) &&
- aWindow->IsMemberClass(GetClassIDFromName("TWindow")) &&
- aWindow->IsShown()) {
-
- aWindow->GetTitle(itsTitle);
- AppendMenu(windowsMenu,itsTitle);
- }
- }
- listOfWindows->Free(); // don't free the TWindows now!
- }
- //----------------------------------------------------------------------------------------
- // TWindowMenuApp::MakeWindowList:
- //----------------------------------------------------------------------------------------
- #pragma segment MAWindowRes
- pascal TList * TWindowMenuApp::MakeWindowList()
- {
-
- WindowPtr * it = (WindowPtr *)WindowList;
- WindowPeek aWindowRec = (WindowPeek)*it; // NOTE: Low mem. global
- WindowPtr aWindowPtr = *it;
-
- TList *listOfWindows = NewList();
-
- // This works because we know that MacApp places a reference to the
- // TWindow that "owns" each "WMgrWindow" in the Window Manager's
- // window list.
-
- do
- {
- listOfWindows->InsertLast((TWindow *)GetWRefCon(aWindowPtr));
- aWindowRec = aWindowRec->nextWindow;
- aWindowPtr = (WindowPtr)aWindowRec;
- } while (aWindowRec->nextWindow);
-
- return listOfWindows;
- }
-
- //----------------------------------------------------------------------------------------
- // TWindowMenuApp::CascadeWindows:
- //----------------------------------------------------------------------------------------
- #pragma segment MAWindowNonRes
- pascal void TWindowMenuApp::CascadeWindows()
- {
- TList *listOfWindows = MakeWindowList();
-
- // Now we traverse the list backward, adjusting window locations as we go
-
- CRect bounds = gStandardWindowMoveBounds;
- bounds.top+=GetMBarHeight();
- for(ArrayIndex i = listOfWindows->GetSize();i>0; i--) {
- TWindow *aWindow = (TWindow *)listOfWindows->At(i);
-
- // Here we're being *REAL* careful. The thing must be:
- // 1) an Object
- // 2) a TWindow
- // 3) Visible
- // The reason for all this is that MacApp maintains at least 1 offscreen
- // window that we need to leave alone (the clipboard window).
-
- if(IsObject(aWindow) &&
- aWindow->IsMemberClass(GetClassIDFromName("TWindow")) &&
- aWindow->IsShown()) {
-
- // Why not use TWindow::SimpleStagger? Because I couldn't get it to
- // work. Somebody should figure out why before we go live! WLC
-
- aWindow->Select();
- aWindow->Locate(bounds[topLeft], kDontInvalidate);
- bounds.top+=kStdStaggerAmount;
- bounds.left+=kStdStaggerAmount;
- }
- }
- listOfWindows->Free(); // don't free the TWindows now!
- }
-
- //----------------------------------------------------------------------------------------
- // TWindowMenuApp::CloseAllWindows:
- //----------------------------------------------------------------------------------------
- #pragma segment MAWindowNonRes
- pascal void TWindowMenuApp::CloseAllWindows()
- {
-
- TList *listOfWindows = MakeWindowList();
-
- // Now we traverse the list, closing as we go (front to back)
-
- for(ArrayIndex i = 1;i<=listOfWindows->GetSize(); i++) {
- TWindow *aWindow = (TWindow *)listOfWindows->At(i);
-
- // Here we're being *REAL* careful. The thing must be:
- // 1) an Object
- // 2) a TWindow
- // 3) Visible
- // The reason for all this is that MacApp maintains at least 1 offscreen
- // window that we need to leave alone (the clipboard window).
-
- if(IsObject(aWindow) &&
- aWindow->IsMemberClass(GetClassIDFromName("TWindow")) &&
- aWindow->IsShown()) {
- aWindow->CloseByUser();
- }
- }
- listOfWindows->Free(); // don't free the TWindows now!
- }
- #pragma segment ASelCommand
- pascal void TWindowMenuApp::DoWindowsMenuItem(short item)
- {
- CStr255 windowTitle, itsTitle;
- MenuHandle windowsMenu = MAGetMenu(mWindows);
-
- GetItem(windowsMenu, item, windowTitle);
-
- TList *listOfWindows = MakeWindowList();
- for(ArrayIndex i = 1; i<=listOfWindows->GetSize(); i++) {
- TWindow *aWindow = (TWindow *)listOfWindows->At(i);
-
- if(IsObject(aWindow) &&
- aWindow->IsMemberClass(GetClassIDFromName("TWindow")) &&
- aWindow->IsShown()) {
-
- aWindow->GetTitle(itsTitle);
- if(itsTitle == windowTitle) {
- aWindow->Select();
- break;
- }
- }
- }
- listOfWindows->Free(); // don't free the TWindows now!
- }
-
-